package com.demo.consumer;

import com.demo.controller.consumerFrom.OrderLogConsumerFrom;
import com.demo.model.OrderLog;
import com.demo.service.impl.OrderLogServiceImpl;
import com.demo.utils.CommonUtil;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigInteger;

@Component
@RocketMQMessageListener(consumerGroup = "order_log_order",topic = "order_log")
public class OrderLogConsumer implements RocketMQListener<OrderLogConsumerFrom> {
    @Resource
    private OrderLogServiceImpl orderLogService;
    @Override
    public void onMessage(OrderLogConsumerFrom orderLogConsumerFrom) {
        OrderLog build = OrderLog.builder().createTime(CommonUtil.dataLocalDatePares())
                .orderId(orderLogConsumerFrom.getOrderId())
                .userId(orderLogConsumerFrom.getUserId())
                .orderLog(orderLogConsumerFrom.getOrderLog()).build();
        boolean save = orderLogService.save(build);
        if (!save) System.out.println("生成日志失败");

    }
}
